import $ from 'jquery';
import QS from 'qs';

export default{
    get(url, param) {
        return new Promise(function(resolve, reject) {
            $.ajax({
                url: url,
                type: 'GET',
                data: param.data || '',
                headers: param.headers || {},
                success: function(res) {
                    resolve(res);
                },
                error: function(error) {
                    reject(error);
                }
            });
        });
    },
    post(url, param) {
        return new Promise(function(resolve, reject) {
            $.ajax({
                url: url,
                type: 'POST',
                data: QS.stringify(param.data),
                headers: param.headers || {},
                success: function(res) {
                    resolve(res);
                },
                error: function(error) {
                    reject(error);
                }
            });
        });
    }
};